import { defineStore } from 'pinia'

export const useMenuStore = defineStore('menu', {
  //state是一个函数， 返回的是对应数据
  state: () => {
    return {
      isCollapse: false,
      menus: [
        {
          name: 'home', title: '首页', icon: 'House', children: [
            { name: 'home', title: 'POKENMAN数据', path: '/home' }
          ]
        },
        {
          name: 'trainer', title: '训练师中心', icon: 'User', children: [
            { name: 'user', title: '用户管理', path: '/user' },
          ]
        },
        {
          name: 'warehouse', title: '仓库', icon: 'Star', children: [
            { name: 'petWarehouse', title: '宠物仓库', path: '/petWarehouse' },
          ]
        },
        {
          name: 'plugin', title: '小试插件', icon: 'Promotion', children: [
            { name: 'edit', title: '文本编辑器', path: '/editor' },
            { name: 'uploadImg', title: '图片墙', path: '/uploadImg' },
          ]
        },
        {
          name: 'inner', title: '内嵌页面', icon: 'Share', children: [
            { name: 'blog', title: '作者博客', path: '/blog' },
            { name: 'starRoaming', title: '星空漫游', path: '/starRoaming' }
          ]
        },
      ],
    }
  },
  getters: {
    // 面包屑数组
    breadArr(): any {
      return this.menus.map(menu => {
        const children = menu.children.map(cmenu => {
          return { title: cmenu.title, path: cmenu.path }
        })
        return { title: menu.title, children }
      })
    },
    // 当前所选menu位置
    currentMenu(): string {
      return sessionStorage.getItem('currentMenu') || 'home'
    }
  },
})